<template>
	<view class="center">
		<view class="logo">
			<image class="logo-img" src="/static/uni-center/logo.png"></image>
			<view class="logo-title">
				<text class="uer-name">{{userName}}</text>
			</view>
		</view>
		<view class="center-list">
			<view class="center-list-item border-bottom">
				<text class="list-icon">&#xe60f;</text>
				<text class="list-text">帐号管理</text>
				<text class="navigat-arrow">&#xe65e;</text>
			</view>
			<view class="center-list-item" @click="updPassword()">
				<text class="list-icon">&#xe639;</text>
				<text class="list-text">修改密码</text>
				<text class="navigat-arrow">&#xe65e;</text>
			</view>
		</view>
		<view class="center-list">
			<view class="center-list-item border-bottom" @click="dbBackUp()">
				<text class="list-icon">&#xe60b;</text>
				<text class="list-text">备份</text>
				<text class="navigat-arrow">&#xe65e;</text>
			</view>
			<view class="center-list-item" @click="dbRestore()">
				<text class="list-icon">&#xe65f;</text>
				<text class="list-text">还原</text>
				<text class="navigat-arrow">&#xe65e;</text>
			</view>
		</view>
		<view class="center-list">
			<view class="center-list-item" @click="logout()">
				<text class="list-icon">&#xe614;</text>
				<text class="list-text">退出</text>
				<text class="navigat-arrow">&#xe65e;</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userName:"",
				name:""
			}
		},
		onLoad() {
			uni.getStorage({
				key : 'user',
				success: res=>{
					console.log(res.data.userName);
					this.userName=res.data.userName
				}
			})
		},
		methods: {
			updPassword(){
				uni.navigateTo({
					url:'/pages/main/tabbar/uni-center/updPassword'
				})
			},
			logout(){
				uni.clearStorage({
				  success: function () {
				    console.log('清空成功');
					uni.navigateTo({
						url:'/pages/index/index'
					})
				  }
				});

				
			},
			dbBackUp(){
				uni.request({
					url:'http://8.130.170.106:9999/user/dbBackUp/',
					success: (res) => {
						if(res.data.length!=0){
							uni.setStorage({
								key:'name',
								data: res.data,
								success() {
									console.log(res.data)
								}
							});
							uni.showToast({
								title: '备份成功',
							})
						}else{
							uni.showToast({
								title: '备份失败',
							})
						}
					}
				})
			},
			dbRestore(){
				uni.getStorage({
					key : 'name',
					success: res=>{
						console.log(res.data);
						this.name=res.data;
						 // 在成功回调中发送请求
						uni.request({
							url: 'http://8.130.170.106:9999/user/dbRestore/',
							data: {
								name: this.name
							},
							success: () => {
								uni.showToast({
									title: '还原成功',
								})
							}
						});
					}
				})
				
			}
		}
	}
</script>

<style>
	@font-face {
		font-family: texticons;
		font-weight: normal;
		font-style: normal;
		src: url('https://at.alicdn.com/t/font_984210_5cs13ndgqsn.ttf') format('truetype');
	}

	page,
	view {
		display: flex;
	}

	page {
		background-color: #f8f8f8;
	}

	.center {
		flex-direction: column;
	}

	.logo {
		width: 750upx;
		height: 240upx;
		padding: 20upx;
		box-sizing: border-box;
		background-color: #4cd964;
		flex-direction: row;
		align-items: center;
	}

	.logo-hover {
		opacity: 0.8;
	}

	.logo-img {
		width: 150upx;
		height: 150upx;
		border-radius: 150upx;
	}

	.logo-title {
		height: 150upx;
		flex: 1;
		align-items: center;
		justify-content: space-between;
		flex-direction: row;
		margin-left: 20upx;
	}

	.uer-name {
		height: 60upx;
		line-height: 60upx;
		font-size: 38upx;
		color: #FFFFFF;
	}

	.go-login.navigat-arrow {
		font-size: 38upx;
		color: #FFFFFF;
	}

	.login-title {
		height: 150upx;
		align-items: self-start;
		justify-content: center;
		flex-direction: column;
		margin-left: 20upx;
	}

	.center-list {
		background-color: #FFFFFF;
		margin-top: 20upx;
		width: 750upx;
		flex-direction: column;
	}

	.center-list-item {
		height: 90upx;
		width: 750upx;
		box-sizing: border-box;
		flex-direction: row;
		padding: 0upx 20upx;
	}

	.border-bottom {
		border-bottom-width: 1upx;
		border-color: #c8c7cc;
		border-bottom-style: solid;
	}

	.list-icon {
		width: 40upx;
		height: 90upx;
		line-height: 90upx;
		font-size: 34upx;
		color: #4cd964;
		text-align: center;
		font-family: texticons;
		margin-right: 20upx;
	}

	.list-text {
		height: 90upx;
		line-height: 90upx;
		font-size: 34upx;
		color: #555;
		flex: 1;
		text-align: left;
	}

	.navigat-arrow {
		height: 90upx;
		width: 40upx;
		line-height: 90upx;
		font-size: 34upx;
		color: #555;
		text-align: right;
		font-family: texticons;
	}
</style>